package edu.nf.project.webs.storeOperation;

import edu.nf.project.entitys.dto.storeOperation.RefundProcessDTO;
import edu.nf.project.entitys.entity.storeOperation.convention.operate.RefundRequest;
import edu.nf.project.services.response.BaseController;
import edu.nf.project.services.response.ResultVO;
import edu.nf.project.services.storeOperation.RefundRequestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author CSY
 * @date 2025 - 06 - 22
 */
@RestController
@RequestMapping("/api/refund-request")
public class RefundRequestController extends BaseController {
    @Autowired
    private RefundRequestService refundRequestService;

    @GetMapping("/{uId}")
    public ResultVO<List<RefundRequest>> listRefundRequestByUserId(@PathVariable Integer uId){
        List<RefundRequest> refundRequests = refundRequestService.listRefundRequestByUserId(uId);
        return success(refundRequests);
    }

    @GetMapping("/request/{rrId}")
    public ResultVO<RefundRequest> getRefundRequestById(@PathVariable Integer rrId){
        RefundRequest refundRequest = refundRequestService.getRefundRequestById(rrId);
        return success(refundRequest);
    }

    @PostMapping("/cancel/{rrId}")
    public ResultVO<String> cancelRefundRequestById(@PathVariable Integer rrId){
        refundRequestService.cancelRefundRequestById(rrId);
        return success();
    }

    @PostMapping("/update")
    public ResultVO<String> updateRefundRequest(@RequestBody RefundRequest refundRequest){
        refundRequestService.updateRefundRequest(refundRequest);
        return success();
    }

    @PostMapping("/process-refund")
    public ResultVO<String> processRefund(@RequestBody RefundProcessDTO refundProcessDTO){
        refundRequestService.processRefund(refundProcessDTO.getRefundRequest(), refundProcessDTO.getPayWay());
        return success();
    }
}
